import 'package:flutter/material.dart';

class ColorInheritedModel extends InheritedModel<String> {
  final Color color;
  final Function() changeColor;

  const ColorInheritedModel({
    Key? key,
    required this.color,
    required this.changeColor,
    required Widget child,
  }) : super(key: key, child: child);

  static ColorInheritedModel? of(BuildContext context, String aspect) {
    return InheritedModel.inheritFrom<ColorInheritedModel>(
      context,
      aspect: aspect,
    );
  }

  @override
  bool updateShouldNotify(ColorInheritedModel oldWidget) {
    return oldWidget.color != color;
  }

  @override
  bool updateShouldNotifyDependent(
    ColorInheritedModel oldWidget,
    Set<String> dependencies,
  ) {
    return dependencies.contains('color') && oldWidget.color != color;
  }
}
